﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;

namespace PhotoUploader
{
    public partial class FormAddNewInterfaceConfig : MetroForm
    {
        private InterfaceConfig _data = new InterfaceConfig();
        public InterfaceConfig Data
        {
            get { return _data; }
        }

        //private List<TextBox> listTextboxs = new List<TextBox>();

        //private void InitCtrls()
        //{

        //}

        public FormAddNewInterfaceConfig()
        {
            InitializeComponent();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (CheckInputing())
            {
                UpdateData();
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }          
        }

        private void UpdateData()
        {
            _data.ID = (int)numericUpDownID.Value;
            _data.InterfaceName = textBoxInterfaceName.Text;
            _data.Timeout = (int)numericUpDownTimeout.Value;
            _data.TypeName = textBoxClassName.Text;
            _data.Enable = metroToggleEnabled.Checked;
            _data.DllName = textBoxDllName.Text;
            _data.Directory = textBoxDllDir.Text;
            _data.ChineseDescrtiption = textBoxDescription.Text;
        }

        private bool CheckInputing()
        {
            if (string.IsNullOrEmpty(textBoxClassName.Text))
            {
                MessageBox.Show("类名不能为空");
                return false;
            }
            if (string.IsNullOrEmpty(textBoxInterfaceName.Text))
            {
                MessageBox.Show("接口名称不能为空");
                return false;
            }
            if (string.IsNullOrEmpty(textBoxDllName.Text))
            {
                MessageBox.Show("动态库名称不能为空");
                return false;
            }
            if (string.IsNullOrEmpty(textBoxDllDir.Text))
            {
                MessageBox.Show("动态库目录不能为空");
                return false;
            }
            if (string.IsNullOrEmpty(textBoxDescription.Text))
            {
                MessageBox.Show("接口描述不能为空");
                return false;
            }
            return true;
        }
    }
}
